<?php
date_default_timezone_set("prc");
//设定用于一个脚本中所有日期时间函数的默认时区说明

//连接数据库
$dsn = "mysql:host=127.0.0.1;dbname=blog";
$db = new pdo($dsn,"root","123456");

//更改默认的utf8为utf8mb4以防中文乱码
$db->exec("set names utf8mb4");

//查询
$sql = "select * from article order by article_id asc ";
$result = $db->query($sql);
$articleList = $result->fetchAll(pdo::FETCH_ASSOC);

?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="css/base.css" />
    <link rel="stylesheet" type="text/css" href="css/top.css" />
    <link rel="stylesheet" type="text/css" href="css/right.css" />
    <link rel="stylesheet" type="text/css" href="css/left.css" />
</head>
<body>
<div id="container">
    <div id="top">
        <div id="top_left">
            <span>博客管理系统</span>
        </div>
        <div id="top_right">
            欢迎你：admin <a href="#">退出登录</a>
        </div>
    </div>
    <div id="left">
        <ul>
            <li><a href="#">分类管理</a></li>
            <li><a href="#" id="left_two">文章管理</a></li>
            <li><a href="#">管理员</a></li>
        </ul>
    </div>
    <div id="right">
        <ul>
            <li>
                <a href="#">首页</a>&nbsp;>
                <a href="#">文章管理</a>&nbsp;>
                <a href="#">文章列表</a>
            </li>
            <li>
                <button id="all">全选</button>
                <a id="multi_delete" href="#">删除选中文章</a>
                <a id="add" href="article_add.php" style="float: right">增加文章</a>
            </li>
            <li>
                <form id="multi-delete-form" action="#">
                    <table class="list">
                        <tbody>
                        <tr>
                            <th></th>
                            <th>文章ID</th>
                            <th>分类ID</th>
                            <th>文章标题</th>
                            <th>文章简介</th>
                            <th>文章内容</th>
                            <th>修改时间</th>
                            <th>增加时间</th>
                            <th>操作</th>
                        </tr>
                        <?php foreach ($articleList as $item): ?>
                            <tr>
                                <td><input type="checkbox"></td>
                                <td><?php echo $item['article_id'] ?></td>
                                <td><?php echo $item['category_id'] ?></td>
                                <td><?php echo $item['article_title'] ?></td>
                                <td><?php echo $item['article_intro'] ?></td>
                                <td><?php echo $item['content'] ?></td>
                                <td><?php echo date("Y-m-d H:i:s",$item['update_time']) ?></td>
                                <td><?php echo date("Y-d-m H:i:s",$item['add_time']) ?></td>
                                <td>
                                    <a class="update" href="article_edit.php?article_id=<?php echo $item['article_id'] ?>">编辑</a>
                                    <a class="delete" href="article_delete.php?article_id=<?php echo $item['article_id'] ?>">删除</a>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                        </tbody>
                    </table>
                </form>
            </li>
        </ul>
    </div>
</div>
</body>
</html>
